package com.colin.app.activity.view.recyclerWithDelete;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.colin.app.R;
import com.colin.app.activity.view.ViewContract;
import com.colin.app.activity.view.ViewPresenterImpl;
import com.colin.app.adapter.TextMoreAdapter;
import com.colin.app.app.AppActivity;
import com.colin.app.bean.DemoBean;
import com.colin.library.help.LogHelp;

public class DeleteViewInRecyclerItemActivity extends AppActivity implements ViewContract.ViewView, TextMoreAdapter.IonSlidingViewClickListener {
    private ViewContract.ViewPresenter mViewPresenter = null;
    private RecyclerView recycler_text_more;
    private TextMoreAdapter mAdapter = null;

    @Override
    protected void onDestroy() {
        mAdapter = null;
        mViewPresenter.destroy();
        mViewPresenter = null;
        super.onDestroy();
    }

    @Override
    public void initPresenter() {
        DemoBean demoBean = getIntent().getExtras().getParcelable("clazz");
        mViewPresenter = new ViewPresenterImpl(this, this, demoBean);
    }

    @Override
    public int initViewLayoutID() {
        return R.layout.activity_delete_view_in_recycler_item;
    }

    @Override
    public void initView() {
        this.recycler_text_more = (RecyclerView) this.findViewById(R.id.recycler_text_more);
        initRecyclerView();
    }

    private void initRecyclerView() {
        if (null == mAdapter) {
            mAdapter = new TextMoreAdapter(this);
        }
        this.recycler_text_more.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        this.recycler_text_more.setAdapter(mAdapter);
        this.recycler_text_more.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void initData() {
        mViewPresenter.setData();
    }

    @Override
    public void onItemClick(View view, int position) {
        LogHelp.d(TAG, "点击项：" + position);
    }

    @Override
    public void onDeleteBtnCilck(View view, int position) {
        if (null != mAdapter) {
            LogHelp.d(TAG, "删除项：" + position);
            mAdapter.removeData(position);
        }
    }
}
